package org.firestorm.traficforecast.utils;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;


public class LocaleUtils {
	
	public static void main(String[] args) {
		vietNamLang();
		englishLang();
		getVieNamLang();
	}
	
	public static Properties getVieNamLang(){
		InputStream input = null;
        try {
            Properties props = new Properties();
            input = new FileInputStream("WebContent/lang_vi_VN.properties");
            props.load(input);
            input.close();
            return props;
        } catch (FileNotFoundException ex) {
            Logger.getLogger(LocaleUtils.class.getName()).log(Level.SEVERE, null, ex);
            return null;
        } catch (IOException ex) {
            Logger.getLogger(LocaleUtils.class.getName()).log(Level.SEVERE, null, ex);
            return null;
        } 
	}
	
	public static Properties getLocale(String location){
		InputStream input = null;
        try {
            Properties props = new Properties();
            input = new FileInputStream(location);
            props.load(input);
            input.close();
            return props;
        } catch (FileNotFoundException ex) {
            Logger.getLogger(LocaleUtils.class.getName()).log(Level.SEVERE, null, ex);
            return null;
        } catch (IOException ex) {
            Logger.getLogger(LocaleUtils.class.getName()).log(Level.SEVERE, null, ex);
            return null;
        } 
	}
	
	public static void vietNamLang() {
        Properties props = new Properties();
        OutputStream output = null;
        try {
            output = new FileOutputStream("WebContent/lang_vi_VN.properties");

            props.setProperty("account", "TÃ i khoáº£n");
            props.setProperty("password", "Máº­t kháº©u");
            props.setProperty("login", "Ä�Äƒng nháº­p");
            props.setProperty("forgot_password", "QuÃªn máº­t kháº©u");
            
            props.store(output, "Thuat ngu Tieng Viet");
        } catch (FileNotFoundException ex) {
            Logger.getLogger(LocaleUtils.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(LocaleUtils.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
	
	public static void englishLang() {
        Properties props = new Properties();
        OutputStream output = null;
        try {
            output = new FileOutputStream("WebContent/lang_en_US.properties");

            props.setProperty("account", "Account");
            props.setProperty("password", "Password");
            props.setProperty("login", "Login");
            props.setProperty("forgot_password", "Forgot password");
            
            props.store(output, "Thuat ngu Tieng Viet");
        } catch (FileNotFoundException ex) {
            Logger.getLogger(LocaleUtils.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(LocaleUtils.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
